package com.maila.xiaoaodispatch.activity;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.cjj.MaterialRefreshLayout;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.maila.xiaoaodispatch.R;
import com.maila.xiaoaodispatch.adpter.PersonalAdapter;
import com.maila.xiaoaodispatch.api.DispatchApi;
import com.maila.xiaoaodispatch.entity.PersonCenterData;
import com.maila.xiaoaodispatch.net.VolleyInterface;
import com.maila.xiaoaodispatch.utils.Constants;
import com.maila.xiaoaodispatch.utils.StartActivityUtils;
import com.maila.xiaoaodispatch.widget.NoScrollListView;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/4.
 */

public class PersonalActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.save_information_tv)
    ImageView btnMywallet;
    @BindView(R.id.user_icon)
    ImageView userIcon;
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.agent_level_ll)
    AutoLinearLayout agentLevelLl;
    @BindView(R.id.user_background)
    AutoRelativeLayout userBackground;
    @BindView(R.id.lv_order)
    NoScrollListView lvOrder;
    @BindView(R.id.hot_refresh)
    MaterialRefreshLayout hotRefresh;
    PersonalAdapter personalAdapter;
    Gson gson = new Gson();
    @BindView(R.id.tv_zonghe)
    TextView tvZonghe;
    @BindView(R.id.tv_order_num)
    TextView tvOrderNum;
    @BindView(R.id.tv_one_num)
    TextView tvOneNum;
    @BindView(R.id.tv_two_num)
    TextView tvTwoNum;
    @BindView(R.id.tv_three_num)
    TextView tvThreeNum;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person);
        ButterKnife.bind(this);
        personalAdapter = new PersonalAdapter(this);
        lvOrder.setAdapter(personalAdapter);
        initdata();
    }

    /**
     *
     */
    private void initdata() {
        new DispatchApi(this, new VolleyInterface() {
            @Override
            public void onSuccess(String result) {
                try {
                    PersonCenterData personCenterData = gson.fromJson(result, PersonCenterData.class);
                    if (personCenterData.getResult() == 1) {
                        tvOneNum.setText(personCenterData.getData().getWorse());
                        tvTwoNum.setText(personCenterData.getData().getNormal());
                        tvThreeNum.setText(personCenterData.getData().getExellent());
                        Glide.with(PersonalActivity.this).load(Uri.parse(Constants.URL_ROOT_XIAOAO + personCenterData.getData().getImg())).into(userIcon);
                        tvZonghe.setText(personCenterData.getData().getGeneral());
                        tvOrderNum.setText(personCenterData.getData().getOrder_all());
                    } else {

                    }
                } catch (JsonSyntaxException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(VolleyError error) {

            }
        }).getmy_evaluate();
    }

    @OnClick({R.id.white_return_iv, R.id.save_information_tv, R.id.agent_level_ll})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.white_return_iv:
                finish();
                break;
            case R.id.save_information_tv:
                StartActivityUtils.start(this, MyWalletActivity.class);
                break;
            case R.id.agent_level_ll:
                StartActivityUtils.start(this, PersonalDataActivity.class);
                break;
        }
    }
}
